//
//  ReversiBoardViewString.m
//  Reversi
//
//  Created by 成瀬 龍人 on 2/4/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "ReversiBoardViewString.h"


@implementation ReversiBoardViewString
- (id)init{
	[super init];
	board = [[NSMutableString alloc] init];
	[board appendString:@" abcdefgh\n"];
	[board appendString:@"1++++++++\n"];
	[board appendString:@"2++++++++\n"];
	[board appendString:@"3++++++++\n"];
	[board appendString:@"4+++@O+++\n"];
	[board appendString:@"5+++O@+++\n"];
	[board appendString:@"6++++++++\n"];
	[board appendString:@"7++++++++\n"];
	[board appendString:@"8++++++++\n"];
	[boardField setStringValue:board];
	return self;
}

- (id)initWithBoard:(ReversiBoard*)aBoard{
	[super init];
	board = [[NSMutableString alloc] init];
	[board appendString:@" abcdefgh\n"];
	for(int y = 1; y <= 8; ++y){
		[board appendString:[[NSString alloc] initWithFormat:@"%d",y]];
		for(int x = 1; x <= 8; ++x){
			uint64 pos = int2mask(x, y);
			if([aBoard is:REVERSI_STONE_BLACK mask:pos]){
				[board appendString:@"@"];
			}else if([aBoard is:REVERSI_STONE_WHITE mask:pos]){
				[board appendString:@"O"];
			}else{
				[board appendString:@"+"];
			}
		}
		[board appendString:@"\n"];
	}
	[boardField setStringValue:board];
	return self;
}


- (NSString*)getStringValue{
	return [board description];
}

- (void)put:(ReversiStone)stone pos:(ReversiBoardPosition*)pos{
	int x = 1 + (pos.x - 1);
	int y = 1 + (pos.y - 1);
	int string_pos = y * (8 + 1 + 1) + x;
	NSString* c = stone == REVERSI_STONE_BLACK ? @"@" : @"O";
 	[board replaceCharactersInRange:NSMakeRange(string_pos,1) withString:c];
	[boardField setStringValue:board];
}

- (void)put:(ReversiStone)stone posArray:(NSArray*)pos_array{
	for(ReversiBoardPosition* pos in pos_array){
		[self put:stone pos:pos];
	}
}

- (void)put:(ReversiStone)stone line:(ReversiBoardLineRange*)line{
	for(ReversiBoardPosition* pos in line){
		[self put:stone pos:pos];
	}	
}

- (void)put:(ReversiStone)stone lineArray:(NSArray*)line_array{
	for(ReversiBoardLineRange* line in line_array){
		[self put:stone line:line];
	}
}

@end
